package com.sfac.javaSpringBoot.modules.account.dao;

import com.sfac.javaSpringBoot.modules.account.entity.Role;
import com.sfac.javaSpringBoot.modules.common.entity.SearchBean;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface RoleDao {
    @Insert("insert into account_role(role_name,create_date)" +
            "values(#{roleName},#{createDate})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insertRole(Role role);
    @Update("update account_role set role_name = #{roleName}" +
            "where id = #{id}")
    void editRole(Role role);

    @Delete("delete from account_role where id = #{id}")
    void deleteRole(int id);
    @Select("select * from account_role where id = #{id} or role_name = #{id}")
    List<Role> queryById(String id);
    @Select("select * from account_role")
    List<Role> getRoles();

    @Select("<script>"
            + "select * from account_role "
            + "<where> "
            + "<if test='keyword != \"\" and keyword != null'>"
            + " and (role_name like '%${keyword}%') "
            + "</if>"
            + "</where>"
            + "<choose>"
            + "<when test='orderBy != \"\" and orderBy != null'>"
            + " order by ${orderBy} ${direction}"
            + "</when>"
            + "<otherwise>"
            + " order by id desc"
            + "</otherwise>"
            + "</choose>"
            + "</script>")
    List<Role> getRolesBySearchBean(SearchBean searchBean);

}
